<?php
	
	if( !$this->network->id ) {
		$this->redirect('home');
	}
	if( !$this->user->is_logged ) {
		$this->redirect('signin');
	}
	$db2->query('SELECT 1 FROM users WHERE id="'.$this->user->id.'" AND is_network_admin=1 LIMIT 1');
	if( 0 == $db2->num_rows() ) {
		$this->redirect('dashboard');
	}
	
	$this->load_langfile('inside/global.php');
	$this->load_langfile('inside/admin.php');
	
	$D->page_title	= $this->lang('admdomcontrol_title', array('#SITE_TITLE#'=>$C->SITE_TITLE));
	
	$D->domains	= array();
	$r	= $db2->fetch_field('SELECT `value` FROM settings WHERE `word`="SUPPORTED_EMAIL_DOMAINS"');

	if($r){
		$D->domains = explode(',', $r);
	}
	
	if( isset($_POST['admins']) ) {
		$domains	= trim($_POST['admins']);
		$domains	= trim($domains, ',');
		$domains	= trim($domains);
		$domains	= explode(',', $domains);
		$domains	= array_unique($domains);
		
		$this->db2->query('UPDATE settings SET `value`="0" WHERE `word`="SUPPORTED_EMAIL_DOMAINS" LIMIT 1');
		if( count($domains) && $domains[0] != ""){
			$this->db2->query('UPDATE settings SET `value`="'.implode(', ', $domains).'" WHERE `word`="SUPPORTED_EMAIL_DOMAINS" LIMIT 1');
		}
		$this->redirect( $C->SITE_URL.'admin/domains/msg:saved' );
	}
	
	$this->load_template('admin_domains.php');
	
?>